package com.pro_one.mobile.controller;

import com.pro_one.constant.MessageConstant;
import com.pro_one.entity.Result;
import com.pro_one.pojo.Member;
import com.pro_one.pojo.Setmeal;
import com.pro_one.service.MemberEditService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("/memberedit")
public class MemberEditController {
    @Reference
    private MemberEditService memberEditService;

    /**
     * 根据登录手机号回显会员信息
     * @param logintelephone
     * @return
     */
    @RequestMapping("/findByOldtelephone")
    public Result findByOldtelephone(String logintelephone){
        try {
            Member byOldtelephone = memberEditService.findByOldtelephone(logintelephone);
            return new Result(true, MessageConstant.QUERY_MEMBER_SUCCESS,byOldtelephone);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_MEMBER_FAIL);

        }


    }

    /**
     * 会员信息修改
     * @param map
     * @return
     */
    @RequestMapping("/updateWXMember")
    public Result updateWXMember(@RequestBody Map map){
        for (Object v : map.values()) {
            System.out.println("value= " + v);
        }
        try {
            memberEditService.updateWXMember(map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true,MessageConstant.UPDATE_MEMBER_FAIL);

        }
        return new Result(true,MessageConstant.UPDATE_MEMBER_SUCCESS);
    }

    @RequestMapping("/findsetmealByDate")
    public Result findsetmealByDate(String logintelephone,@RequestBody String[] value1){
        System.out.println(logintelephone);
       List<Object> list=new ArrayList<>();
       list.add(logintelephone);
        for (String s : value1) {
            System.out.println(s);
            list.add(s);
        }
        try {
            List<Map<String,Object>> setmealList = memberEditService.findsetmealByDate(list);
            return new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,setmealList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }
}
